﻿using System.Diagnostics;
using RestSharp;

namespace INdTFramework.Http
{
    /// <summary>
    /// RestSharpWrapper extends the funciontalities of RestClient to provide a
    /// more friendly approach to handle successful and failure requests using
    /// the specialized class <typeparamref name="INdTFramework.Http.HttpRestRequest"/>
    /// </summary>
    public class RestSharpWrapper : RestClient
    {
        /// <summary>
        /// Default constructor receiving baseUrl paramenter.
        /// </summary>
        /// <param name="baseUrl"></param>
        public RestSharpWrapper(string baseUrl) : base(baseUrl) { }

        /// <summary>
        /// Custom async request method passing the type for successful response (T) and
        /// error response (E).
        /// </summary>
        /// <typeparam name="T">Generic parameter for succesful responses</typeparam>
        /// <typeparam name="E">Generic parameter for failure responses</typeparam>
        /// <param name="request">Request instance object</param>
        /// <returns></returns>
        public RestRequestAsyncHandle ExecuteAsync<T, E>(HttpRestRequest<T, E> request)
        {
            Debug.WriteLine (BuildUri(request));
            return base.ExecuteAsync(request, request.Callback);
        }
    }
}
